import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;

import sharedClasses.Action;
import sharedClasses.Play;

//Our test class to try things.
//Right now it adds data from the US vs Brazil Group A pool play match set 1 to the database
public class Run
{

	/**
	 * @param args
	 * @throws FileNotFoundException 
	 */
	public static void main(String[] args) throws FileNotFoundException
	{
		DataIO dio = new DataIO();
		dio.clean();
		dio.addMatch();
		
		ArrayList<Action> actions = new ArrayList<Action>();
//		int[] origin = {5, 0};
//		int[] destination = {1, 50};
//		actions.add(new Action(origin, destination, 0));
//		origin[0] = 19;
//		origin[1] = 32;
//		actions.add(new Action(destination, origin, 0));
//		destination[0] = 1;
//		destination[1] = 32;
//		actions.add(new Action(origin, destination, 0));
//		origin[0] = 0;
//		origin[1] = 10;
//		actions.add(new Action(destination, origin, 1));
//		
//		Play play = new Play();
//		play.Children = new ArrayList<Action>();
//		for (int i = 0; i < actions.size(); i++)
//		{
//			play.Children.add(actions.get(i));
//		}
//		dio.addPlay(play);
//		actions.clear();
//		
//		origin[0] = 5;
//		origin[1] = 0;
//		destination[0] = 2;
//		destination[1] = 51;
//		actions.add(new Action(origin, destination, 0));
//		origin[0] = 19;
//		origin[1] = 32;
//		actions.add(new Action(destination, origin, 0));
//		destination[0] = 1;
//		destination[1] = 34;
//		actions.add(new Action(origin, destination, 0));
//		origin[0] = 2;
//		origin[1] = 3;
//		actions.add(new Action(destination, origin, 1));
//		
//		play = new Play();
//		play.Children = new ArrayList<Action>();
//		for (int i = 0; i < actions.size(); i++)
//		{
//			play.Children.add(actions.get(i));
//		}
//		dio.addPlay(play);
//		actions.clear();
//		
//		origin[0] = 5;
//		origin[1] = 0;
//		destination[0] = 4;
//		destination[1] = 50;
//		actions.add(new Action(origin, destination, 0));
//		origin[0] = 17;
//		origin[1] = 33;
//		actions.add(new Action(destination, origin, 0));
//		destination[0] = 0;
//		destination[1] = 33;
//		actions.add(new Action(origin, destination, 0));
//		origin[0] = 1;
//		origin[1] = 15;
//		actions.add(new Action(destination, origin, 1));
//		
//		play = new Play();
//		play.Children = new ArrayList<Action>();
//		for (int i = 0; i < actions.size(); i++)
//		{
//			play.Children.add(actions.get(i));
//		}
//		dio.addPlay(play);
//		actions.clear();
//		
//		origin[0] = 5;
//		origin[1] = 0;
//		destination[0] = 2;
//		destination[1] = 50;
//		actions.add(new Action(origin, destination, 0));
//		origin[0] = 18;
//		origin[1] = 31;
//		actions.add(new Action(destination, origin, 0));
//		destination[0] = 0;
//		destination[1] = 32;
//		actions.add(new Action(origin, destination, 0));
//		origin[0] = 0;
//		origin[1] = 9;
//		actions.add(new Action(destination, origin, 1));
//		
//		play = new Play();
//		play.Children = new ArrayList<Action>();
//		for (int i = 0; i < actions.size(); i++)
//		{
//			play.Children.add(actions.get(i));
//		}
//		dio.addPlay(play);
//		actions.clear();
		
		Scanner sc = new Scanner(new File("C:\\Users\\CSE User\\Desktop\\vballData.txt"));
		int lastPoint = 0;
		int rotation = 1;
		int[] origin = new int[2];
		int[] destination = new int[2];
		boolean first = true;
		while (sc.hasNext())
		{
			String s = sc.next();
			
			if (!first)
			{
				if (s.contains("+") || s.contains("-"))
				{	
					if (s.contains("+"))
					{
						actions.get(actions.size() - 1).setResult(1);
						if (lastPoint == 1)
						{
							rotation++;
							rotation = rotation % 6;
							if (rotation == 0)
							{
								rotation = 6;
							}
						}
						lastPoint = 0;
						
					}
					else
					{
						actions.get(actions.size() - 1).setResult(-1);
						lastPoint = 1;
					}
					Play temp = new Play();
					temp.Rotation = rotation;
					temp.Children = new ArrayList<Action>();
					for (int i = 0; i < actions.size(); i++)
					{
						temp.Children.add(actions.get(i));
					}
					dio.addPlay(temp);
					actions.clear();
					first = true;
				}
				else
				{
					destination[0] = Integer.parseInt(s);
					destination[1] = Integer.parseInt(sc.next());
					actions.add(new Action(origin, destination, 0));
				}
				
				origin[0] = destination[0];
				origin[1] = destination[1];
			}
			else
			{
				origin[0] = Integer.parseInt(s);
				origin[1] = Integer.parseInt(sc.next());
				first = false;
			}
		}
		
		//-------------------END OF INSERT------------------------
		
//		Action[] array = dio.getAllActions();
//		
//		int[][] originCoords = new int[array.length][2];
//		
//		for (int i = 0; i < array.length; i++)
//		{
//			originCoords[i][0] = array[i].getOrigin()[0];
//			originCoords[i][1] = array[i].getOrigin()[1];
//		}
//		
//		int[][] weightMap = Engine.convertCoordsToWeightMap(originCoords);
//		Engine.printInput(weightMap);
//		System.out.println();
//		
//		double[][] hotspotMap = Engine.findHotspots(weightMap, 2);
//		Engine.printInput(hotspotMap);
		
		//hotspotMap = Engine.findHotspots(hotspotMap, 1);
		//Engine.printInput(hotspotMap);
			
		
//		Play[] plays = dio.getAllPlays_HACK();
//		
//		Play pattern = Engine.findStrongestPattern(plays);
//		
//		System.out.println("Found pattern!");
//		
//		for (int i = 0; i < 6; i++)
//		{
//			plays = dio.getPlays(i+1);
//			Engine.findStrongestPattern(plays);
//		}
		
//		for (int i = 0; i < pattern.length; i++)
//		{
//			System.out.println("(" + pattern[i][0] + ", " + pattern[i][1] + ")");
//		}
		
//		dio.clean();
		dio.close();

	}

}
